package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Zuopinleibie;
import com.example.exception.CustomException;
import com.example.service.ZuopinleibieService;
import com.example.vo.ZuopinleibieVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("zuopinleibieService")
public class ZuopinleibieServiceImpl extends ServiceImpl<ZuopinleibieDao, Zuopinleibie> implements ZuopinleibieService {

    @Resource
    private ZuopinleibieDao zuopinleibieDao;

    public Zuopinleibie add(Zuopinleibie zuopinleibie) {
		
	   //youquchong1
        zuopinleibie.setAddtime(new Date());
        zuopinleibieDao.insert(zuopinleibie);
        return zuopinleibie;
    }
	
	
	
    public void delete(Long id) {
        zuopinleibieDao.deleteById(id);
    }
	

    public void update(Zuopinleibie zuopinleibie) {
        //youquchong2
        zuopinleibieDao.updateById(zuopinleibie);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return zuopinleibieDao.daochuexcel();
    }

    @Override
    public Zuopinleibie findById(Integer id) {
        return zuopinleibieDao.selectById(id);
    }

    public ZuopinleibieVo findPage(ZuopinleibieVo zuopinleibieVo) {
        LambdaQueryWrapper<Zuopinleibie> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(zuopinleibieVo.getZuopinjingsai()), Zuopinleibie::getZuopinjingsai,zuopinleibieVo.getZuopinjingsai());        
        Page<Zuopinleibie> page = new Page<>(zuopinleibieVo.getCurrent(),zuopinleibieVo.getCurrentNum());
        zuopinleibieDao.selectPage(page,wrapper);
        List<Zuopinleibie> zuopinleibies = page.getRecords();
        zuopinleibieVo.setList(zuopinleibies);
        zuopinleibieVo.setPages(page.getPages());
        zuopinleibieVo.setTotal(page.getTotal());
        zuopinleibieVo.setCurrent(page.getCurrent());
        zuopinleibieVo.setCurrentNum(page.getSize());
        return zuopinleibieVo;
    }

    @Override
    public void deleteList(List<Zuopinleibie> list) {
        List<Integer> ids =  list.stream().map(Zuopinleibie::getId).collect(Collectors.toList());
        zuopinleibieDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
